package cardmanager;

import cardmanager.enums.CardAttribute;
import cardmanager.enums.CardRace;
import cardmanager.enums.CardType;

public class CardInfo implements Cloneable {

    private String m_cardRaces;
    private String m_cardTypes;
    private int aliasId;
    private int atk;
    private int attribute;
    private int def;
    private String description;
    private int id;
    private int level;
    private String name;
    private int race;
    private int type;
    public int count = 1;
    
    public CardInfo(int id, int alias, int atk, int def, int attribute,
    		int level,int race, int type){
    	this.id = id;this.aliasId = alias; this.atk = atk; this.def = def; 
    	this.attribute = attribute;this.level = level; this.race = race;this.type = type;
    }
    @Override
	public CardInfo clone() throws CloneNotSupportedException
    {
    return (CardInfo)super.clone();
    }
    public void setText(String name,String description){
    	this.name = name;
    	this.description = description;
    }
    public int getId(){
    	return id;
    }
    public int getAlias(){
    	return aliasId;
    }
    public int getAtk(){
    	return atk;
    }
    public int getDef(){
    	return def;
    }
    public int getAttribute(){
    	return attribute;
    }
    public String getName(){
    	return name;
    }
    public String getDescription(){
    	return description;
    }
    public int getLevel(){
    	return level;
    }
    public int getRace(){
    	return race;
    }
    public int getType(){
    	return type;
    }
    public String getCardRace()
    {
        if (this.m_cardRaces != null)
        {
            return this.m_cardRaces;
        }
        CardRace[] raceArray = new CardRace[] { 
            CardRace.Warrior, CardRace.SpellCaster, CardRace.Fairy, CardRace.Fiend, CardRace.Zombie, CardRace.Machine, CardRace.Aqua, CardRace.Pyro, CardRace.Rock, CardRace.WingBeast, CardRace.Plant, CardRace.Insect, CardRace.Thunder, CardRace.Dragon, CardRace.Beast, CardRace.BeastWarrior, 
            CardRace.Dinosaur, CardRace.Fish, CardRace.SeaSerpent, CardRace.Reptile, CardRace.Psychic, CardRace.DivineBeast
         };
        CardAttribute[] attributeArray = new CardAttribute[] { CardAttribute.Dark, CardAttribute.Divine, CardAttribute.Earth, CardAttribute.Fire, CardAttribute.Light, CardAttribute.Water, CardAttribute.Wind };

        for(int i = 0; i < raceArray.length; i++){
            if ((this.race & raceArray[i].getValue()) != 0)
            {
                this.m_cardRaces = raceArray[i].toString();
                break;
            }
        }
        for(int i = 0; i < attributeArray.length; i++){
            if ((this.attribute & attributeArray[i].getValue()) != 0)
            {
                this.m_cardRaces = this.m_cardRaces + " - " + attributeArray[i].toString();
                break;
            }
        }
        return (this.m_cardRaces == null ? (this.m_cardRaces = ""): this.m_cardRaces);
    }
    public String getCardTypes()
    {
        if (this.m_cardTypes == null)
        {
            CardType[] typeArray = new CardType[] { 
                CardType.Monster, CardType.Spell, CardType.Trap, CardType.Normal, CardType.Effect, CardType.Fusion, CardType.Ritual, CardType.TrapMonster, CardType.Spirit, CardType.Union, CardType.Dual, CardType.Tuner, CardType.Synchro, CardType.Token, CardType.QuickPlay, CardType.Continuous, 
                CardType.Equip, CardType.Field, CardType.Counter, CardType.Flip, CardType.Toon, CardType.Xyz
             };
            
            for(int i = 0; i < typeArray.length; i++){
                if (((this.type & typeArray[i].getValue()) != 0))
                {
                    if (this.m_cardTypes == null)
                    {
                        this.m_cardTypes = typeArray[i].toString();
                    }
                    else
                    {
                        this.m_cardTypes = this.m_cardTypes + " / " + typeArray[i].toString();
                    }
                }
            }
            this.m_cardTypes = "[" + this.m_cardTypes + "]";
        }
        return this.m_cardTypes;
    }
    
    public boolean hasType(CardType type)
    {
        return ((this.type & type.getValue()) != 0);
    }

    public boolean isExtraCard()
    {
        if (!this.hasType(CardType.Fusion) && !this.hasType(CardType.Synchro))
        {
            return this.hasType(CardType.Xyz);
        }
        return true;
    }
    
}
